package com.itheima.mapper;

import com.itheima.entity.Emp;
import com.itheima.entity.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Mapper
public interface EmpMapper {
    /**
     * 统计员工总记录数
     * @return
     */
    // @Select("select count(*) from emp")
    // Long count();

    /**
     * 分页查询
     * @param start
     * @param pageSize
     * @return
     */
    // @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id limit #{start}, #{pageSize}")
    // List<Emp> page(Integer start, Integer pageSize);

    /**
     * 列表查询
     * @return
     */
    // @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id")
    // 基于XML开发--动态SQL
    List<Emp> list(EmpQueryParam param);

    @Options(useGeneratedKeys = true, keyProperty = "id") //获取主键的值赋给id
    @Insert("insert into emp values (null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

    void deleteBatch(List<Integer> ids);


//    @Select("select * from emp e left join emp_expr ee on e.id = ee.emp_id where e.id = #{id}")
    Emp getById(Integer id);

    @Select("select * from emp where id = #{id}")
    Emp getById2(Integer id);

    void update(Emp emp);

    List<Emp> getMasterNameByMasterIds(Set<Integer> masterIds);

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectUNandP(Emp emp);
}
